package com.ydl.iec.thrid;

/**
 * @Author : 汪洋
 * @CreateTime : 2023/11/29
 * @Description :
 * @Version : v1.0
 */
import java.io.IOException;


import org.openmuc.j60870.ASdu;
import org.openmuc.j60870.ASduType;
import org.openmuc.j60870.ConnectionEventListener;
import org.openmuc.j60870.ie.InformationObject;

public class J60870ClientListener implements ConnectionEventListener{

    /**
     * 监听从站发来的数据
     * @param aSdu
     */
    @Override
    public void newASdu(ASdu aSdu) {
        //打印数据，效果见下图
//        System.out.println(aSdu.toString());
        if (aSdu.getTypeIdentification().equals(ASduType.M_SP_NA_1)) {
            // 获取ASDU的信息元素集合
            InformationObject[] informationObjects = aSdu.getInformationObjects();

            // 假设你关心的电表数据在Single-Point Information元素中
            for (InformationObject informationObject : informationObjects) {
                System.out.println("class:"+informationObject.getClass());
                System.out.println("inform:" + informationObject.toString());
            }
        }
    }

    /**
     * 监听连接关闭
     * @param cause
     */
    @Override
    public void connectionClosed(IOException cause) {
        cause.printStackTrace();
    }
}
